home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / app / BaseDocument.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  7.5 KB  |  251 lines

  1. package com.extensibility.app;
  2.  
  3. import com.extensibility.print.PageFormatDialog;
  4. import com.extensibility.util.Debug;
  5. import com.extensibility.xml.URI;
  6. import java.awt.Component;
  7. import java.awt.event.ActionEvent;
  8. import java.io.File;
  9. import java.io.IOException;
  10. import java.io.Writer;
  11. import java.util.Enumeration;
  12. import javax.swing.event.ChangeEvent;
  13. import javax.swing.event.ChangeListener;
  14. import javax.swing.event.EventListenerList;
  15. import javax.swing.undo.UndoableEditSupport;
  16.  
  17. public class BaseDocument {
  18.    static int nextUntitledIndex = 1;
  19.    URI baseURI;
  20.    boolean touched;
  21.    boolean virgin;
  22.    int untitledIndex;
  23.    protected WindowUndoManager undoManager;
  24.    protected UndoableEditSupport undoSupport;
  25.    EventListenerList listenerList;
  26.    ChangeEvent changeEvent;
  27.  
  28.    public BaseDocument(URI var1) {
  29.       this.listenerList = new EventListenerList();
  30.       this.changeEvent = new ChangeEvent(this);
  31.       this.baseURI = var1;
  32.       this.undoManager = new WindowUndoManager(this);
  33.       this.undoSupport = new UndoableEditSupport();
  34.       this.undoSupport.addUndoableEditListener(new UndoAdapter(this));
  35.    }
  36.  
  37.    public BaseDocument() {
  38.       this(new URI());
  39.       this.virgin = true;
  40.       this.untitledIndex = nextUntitledIndex++;
  41.    }
  42.  
  43.    public void setURI(URI var1) {
  44.       this.baseURI = var1;
  45.       if (!this.baseURI.hasPersistence()) {
  46.          this.untitledIndex = nextUntitledIndex++;
  47.       }
  48.  
  49.       Enumeration var2 = Desktop.getWindowsOfDocument(this);
  50.  
  51.       while(var2.hasMoreElements()) {
  52.          ((BaseWindow)var2.nextElement()).setTitle();
  53.       }
  54.  
  55.    }
  56.  
  57.    public void touch() {
  58.       this.touched = true;
  59.       this.virgin = false;
  60.    }
  61.  
  62.    public boolean isTouched() {
  63.       return this.touched;
  64.    }
  65.  
  66.    public final boolean isVirgin() {
  67.       return this.virgin;
  68.    }
  69.  
  70.    public final void setVirgin(boolean var1) {
  71.       this.virgin = var1;
  72.       if (var1) {
  73.          this.touched = false;
  74.       }
  75.  
  76.    }
  77.  
  78.    public void setTouched(boolean var1) {
  79.       if (var1) {
  80.          this.touch();
  81.       } else {
  82.          this.touched = var1;
  83.       }
  84.  
  85.    }
  86.  
  87.    public final boolean isReadOnly() {
  88.       return false;
  89.    }
  90.  
  91.    public URI getURI() {
  92.       return this.baseURI;
  93.    }
  94.  
  95.    public String getName() {
  96.       return !this.baseURI.hasPersistence() ? String.valueOf(UI.getString("untitled.window")).concat(String.valueOf(this.untitledIndex == 1 ? "" : String.valueOf("").concat(String.valueOf(this.untitledIndex)))) : this.baseURI.getUIName();
  97.    }
  98.  
  99.    public BaseWindow getWindow(Class var1) {
  100.       return Desktop.findWindow(new 1(var1, this));
  101.    }
  102.  
  103.    public WindowUndoManager getUndoManager() {
  104.       return this.undoManager;
  105.    }
  106.  
  107.    public void startCommand() {
  108.       this.undoSupport.beginUpdate();
  109.    }
  110.  
  111.    public void endCommand() {
  112.       this.undoSupport.endUpdate();
  113.    }
  114.  
  115.    public void performEdit(BaseEdit var1) {
  116.       var1.doCommand();
  117.       this.undoSupport.postEdit(var1);
  118.    }
  119.  
  120.    public String getClassName() {
  121.       return "com.extensibility.xa.BaseDocument";
  122.    }
  123.  
  124.    public void printSetup(ActionEvent var1) {
  125.       PageFormatDialog var2 = DialogFactory.askPageSetup(Desktop.getDialogParent(var1));
  126.       if (!var2.userCanceled()) {
  127.          BaseApplication.getPreferences().updateMargins(var2.getPreferences());
  128.       }
  129.    }
  130.  
  131.    protected String[] getSaveChangesName() {
  132.       return new String[]{this.getName()};
  133.    }
  134.  
  135.    public boolean isOkToClose(BaseWindow var1) {
  136.       if (var1 instanceof EditWindow && !((EditWindow)var1).commitPendingEdits(true)) {
  137.          return false;
  138.       } else if (this.isTouched() && Desktop.isLastWindowOfDocument(var1)) {
  139.          int var2 = DialogFactory.saveChanges(var1, this.getSaveChangesName());
  140.          if (var2 == 0) {
  141.             return this.save(new ActionEvent(var1, 1001, "#DUMMY"));
  142.          } else if (var2 == 1) {
  143.             this.cleanupUnsavedChanges();
  144.             return true;
  145.          } else {
  146.             return false;
  147.          }
  148.       } else {
  149.          return true;
  150.       }
  151.    }
  152.  
  153.    public void saveNotify(URI var1) {
  154.    }
  155.  
  156.    protected Writer createWriter(URI var1) throws IOException {
  157.       return var1.createWriter();
  158.    }
  159.  
  160.    public boolean save(ActionEvent var1) {
  161.       if (!this.isReadOnly() && !this.baseURI.isEmpty()) {
  162.          if (!this.isTouched()) {
  163.             return true;
  164.          } else {
  165.             try {
  166.                Writer var2 = this.createWriter(this.baseURI);
  167.                this.write(var2);
  168.                var2.close();
  169.             } catch (Exception var4) {
  170.                DialogFactory.showException((Component)null, 103, var4, this.getName());
  171.                boolean var3 = false;
  172.                return var3;
  173.             }
  174.  
  175.             this.setTouched(false);
  176.             BaseApplication.getApplication().saveNotify(this.getURI(), this);
  177.             return true;
  178.          }
  179.       } else {
  180.          return this.saveAs(var1);
  181.       }
  182.    }
  183.  
  184.    protected File getSaveAsFile(ActionEvent var1) {
  185.       String[] var2 = BaseApplication.getApplication().getSaveTypes();
  186.       String var3 = "";
  187.       return DialogFactory.askNewFile(Desktop.getDialogParent(var1), var2, var3);
  188.    }
  189.  
  190.    public boolean saveAs(ActionEvent var1) {
  191.       File var2 = this.getSaveAsFile(var1);
  192.       if (var2 == null) {
  193.          return false;
  194.       } else {
  195.          this.setURI(new URI(var2));
  196.          this.touch();
  197.          this.save(var1);
  198.          return true;
  199.       }
  200.    }
  201.  
  202.    public boolean saveAs(URI var1) {
  203.       this.setURI(var1);
  204.       this.touch();
  205.       return this.save((ActionEvent)null);
  206.    }
  207.  
  208.    public void close() {
  209.       BaseApplication.getApplication().fireDocumentClosed(this.getURI());
  210.    }
  211.  
  212.    public void read(URI var1) throws Exception {
  213.       Debug.assertAbstract();
  214.    }
  215.  
  216.    public void write(Writer var1) throws IOException {
  217.       Debug.assertAbstract();
  218.    }
  219.  
  220.    public void addChangeListener(ChangeListener var1) {
  221.       this.listenerList.add(Class.forName("javax.swing.event.ChangeListener"), var1);
  222.    }
  223.  
  224.    public void removeChangeListener(ChangeListener var1) {
  225.       this.listenerList.remove(Class.forName("javax.swing.event.ChangeListener"), var1);
  226.    }
  227.  
  228.    protected void cleanupUnsavedChanges() {
  229.    }
  230.  
  231.    protected void fireChangeEvent() {
  232.       Object[] var1 = this.listenerList.getListenerList();
  233.  
  234.       for(int var2 = var1.length - 2; var2 >= 0; var2 -= 2) {
  235.          if (var1[var2] == Class.forName("javax.swing.event.ChangeListener")) {
  236.             ChangeListener var3 = (ChangeListener)var1[var2 + 1];
  237.             var3.stateChanged(this.changeEvent);
  238.          }
  239.       }
  240.  
  241.    }
  242.  
  243.    public int getDefaultDocWidth() {
  244.       return Desktop.getDefaultDocWidth(this);
  245.    }
  246.  
  247.    public int getDefaultDocHeight() {
  248.       return Desktop.getDefaultDocHeight(this);
  249.    }
  250. }
  251.